<?php

namespace App\Models;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class Order
 * @package App\Models
 * @version September 18, 2017, 5:48 am UTC
 *
 * @property integer user_id
 * @property string sn
 * @property integer status
 * @property integer pay_type
 * @property integer pay_status
 * @property string remark
 * @property integer is_print
 * @property integer goods_number
 * @property decimal price
 * @property decimal discount_price
 * @property decimal calculate_price
 * @property decimal calculate_pay_price
 * @property integer calculate_goods_number
 * @property integer acquire_integral
 * @property integer use_integral
 * @property decimal pay_money
 * @property integer wxpay_record_id
 * @property integer shipping_status
 * @property timestamp shipping_at
 * @property integer will_take
 * @property string express_type
 * @property string express_sn
 * @property string express_info
 * @property string json
 * @property string request_params
 * @property timestamp pay_at
 */
class Order extends Model
{
    use SoftDeletes;

    public $table = 'orders';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'user_id',
        'sn',
        'status',
        'pay_type',
        'pay_status',
        'remark',
        'goods_number',
        'price',
        'is_print',
        'discount_price',
        'calculate_price',
        'calculate_pay_price',
        'calculate_pay_price',
        'calculate_goods_number',
        'acquire_integral',
        'use_integral',
        'pay_money',
        'wxpay_record_id',
        'will_take',
        'is_need_delivery_fee',
        'delivery_fee',
        'express_type',
        'express_sn',
        'express_info',
        'json',
        'address_id',
        'request_params',
        'pay_at',
        'shipping_at',
        'shipping_end_at',

        'merge_id',
        //配送端字段
        'shipping_status',
        'shipping_area',
        //配单
        'pairing_id',
        'pairing_tob_at',
        'pairing_at',
        //验单
        'verifier_id',
        'verify_at',
        'verify_desc',
        'verify_tob_at',
        //配送
        'courier_id',
        'shipping_rob_at',
        'real_shipping_at',
        'real_shipping_end_at',
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'user_id' => 'integer',
        'sn' => 'string',
        'status' => 'integer',
        'pay_type' => 'integer',
        'pay_status' => 'integer',
        'remark' => 'string',
        'goods_number' => 'integer',
        'acquire_integral' => 'integer',
        'use_integral' => 'integer',
        'wxpay_record_id' => 'integer',
        'shipping_status' => 'integer',
        'will_take' => 'integer',
        'express_type' => 'string',
        'express_sn' => 'string',
        'express_info' => 'string',
        'json' => 'string',
        'request_params' => 'string'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        
    ];

    public function goods()
    {
        return $this->hasMany('App\Models\OrderGoods');
    }

    public function address()
    {
        return $this->belongsTo('App\Models\Address');
    }

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function courier()
    {
        return $this->belongsTo('App\User', 'courier_id');
    }

    public function pairing()
    {
        return $this->belongsTo('App\User', 'pairing_id');
    }

    public function verifier()
    {
        return $this->belongsTo('App\User', 'verifier_id');
    }

    public function bonus()
    {
        return $this->hasOne('App\Models\Bonus');
    }

    public function payRecord()
    {
        return $this->hasOne('App\Models\PayRecord');
    }
}
